package com.liujit.upms.controller;

import cn.hutool.core.lang.tree.Tree;
import com.liujit.common.domain.params.BaseParams;
import com.liujit.common.domain.result.PageBean;
import com.liujit.upms.domain.params.SysMenuParams;
import com.liujit.upms.domain.query.SysMenuQuery;
import com.liujit.upms.domain.query.SysMenuTreeQuery;
import com.liujit.upms.domain.result.SysMenuResult;
import com.liujit.upms.service.SysMenuService;
import com.liujit.validator.group.AddGroup;
import com.liujit.validator.group.ModifyGroup;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description 系统菜单管理接口
 * @Author liujun
 * @Date 2021-07-02 14:59:44
 */
@RequiredArgsConstructor
@Api(tags = "系统菜单管理接口")
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController {

    private final SysMenuService sysMenuService;

    @ApiOperation(value = "分页查询", notes = "根据系统菜单分页查询条件，分页查询系统菜单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统菜单分页查询条件", dataType = "SysMenuQuery", dataTypeClass = SysMenuQuery.class, paramType = "query") })
    @GetMapping("/getPage")
    public PageBean<SysMenuResult> getPage(SysMenuQuery query) {
        return sysMenuService.getPage(query);
    }

    @ApiOperation(value = "添加", notes = "根据系统菜单添加请求参数，添加系统菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统菜单添加请求参数", dataType = "SysMenuParams", dataTypeClass = SysMenuParams.class, paramType = "body") })
    @PostMapping("add")
    public Boolean add(@RequestBody @Validated(AddGroup.class) SysMenuParams params) {
        return sysMenuService.save(params);
    }

    @ApiOperation(value = "修改", notes = "根据系统菜单修改请求参数，修改系统菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统菜单修改请求参数", dataType = "SysMenuParams", dataTypeClass = SysMenuParams.class, paramType = "body") })
    @PostMapping("/modify")
    public Boolean modify(@RequestBody @Validated(ModifyGroup.class) SysMenuParams params) {
        return sysMenuService.save(params);
    }

    @ApiOperation(value = "查询", notes = "根据系统菜单id，查询系统菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统菜单id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/get")
    public SysMenuResult get(Long id) {
        return sysMenuService.get(id);
    }

    @ApiOperation(value = "查询详情", notes = "根据系统菜单id，查询系统菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "系统菜单id", dataType = "Long", dataTypeClass = Long.class, paramType = "query") })
    @GetMapping("/getDetail")
    public SysMenuResult getDetail(Long id) {
        return sysMenuService.getDetail(id);
    }

    @ApiOperation(value = "删除", notes = "根据系统菜单删除请求参数，删除系统菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统菜单删除请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/del")
    public Boolean del(@RequestBody BaseParams params) {
        return sysMenuService.del(params);
    }

    @ApiOperation(value = "启用", notes = "根据系统菜单启用请求参数，启用系统菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统菜单启用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/enabled")
    public Boolean enabled(@RequestBody BaseParams params) {
        return sysMenuService.enabled(params);
    }

    @ApiOperation(value = "禁用", notes = "根据系统菜单禁用请求参数，禁用系统菜单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "params", value = "系统菜单禁用请求参数", dataType = "BaseParams", dataTypeClass = BaseParams.class, paramType = "body") })
    @PostMapping("/disabled")
    public Boolean disabled(@RequestBody BaseParams params) {
        return sysMenuService.disabled(params);
    }

    @ApiOperation(value = "查询菜单树形列表", notes = "根据系统菜单树查询条件，查询菜单树形列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "query", value = "系统菜单树查询条件", dataType = "SysMenuTreeQuery", dataTypeClass = SysMenuTreeQuery.class, paramType = "query") })
    @GetMapping("/getTree")
    public List<Tree<Long>> getTree(SysMenuTreeQuery query) {
        return sysMenuService.getTree(query);
    }
}
